﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using core.Models;
using core.Business;
using Newtonsoft.Json;
using System.Text;
using System.Threading;

namespace core.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            DateTime date = Convert.ToDateTime("2014-05-01");
            int count = 0;
            while (true)
            {
                if (date >= Convert.ToDateTime("2014-06-01"))
                {
                    break;
                }
                string a = HttpRequest.HttpGet("https://www.jyc99.com/api/OutInterface/wdzjgetinfo?date=" + date.ToString("yyyy-MM-dd") + "&page=1&pageSize=500", Encoding.GetEncoding("utf-8"));
                WDZJBackInfo req = JsonConvert.DeserializeObject<WDZJBackInfo>(a);
                count += req.totalCount;
                date = date.AddDays(1);
                Thread.Sleep(100);
            }
            ViewData["count"] = count;
            return View();
        }


        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
